<template>
  <div>
    <van-nav-bar title="账号登录" left-arrow @click-left="onClickLeft" />
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        name="username"
        placeholder="请输入账号"
        :rules="[
          { required: true, message: '账号为必填项' },
          {
            pattern: /\w{5,8}/,
            message: '长度为5到8位，只能出现数字、字母、下划线',
          },
        ]"
      />
      <van-field
        v-model="password"
        type="password"
        name="password"
        placeholder="请输入密码"
        :rules="[
          { required: true, message: '密码为必填项' },
          {
            pattern: /\w{5,12}/,
            message: '长度为5到12位，只能出现数字、字母、下划线',
          },
        ]"
      />
      <div style="margin: 16px">
        <van-button block type="primary" native-type="submit">登录</van-button>
      </div>
    </van-form>
    <div class="link">
    <router-link class="ccc" to="/register">还没有账号，去注册~</router-link>

    </div>
  </div>
</template>

<script>
import { setToken } from '@/utils-gongju/storage.js'
import { login } from '@/api-ajax/house.js'
export default {
  name: 'LoginPage',
  data () {
    return {
      username: '',
      password: ''
    }
  },
  methods: {
    async onSubmit (values) {
      // console.log('submit', values)
      const { data } = await login(values)
      // console.log(data.body.token)
      setToken(data.body.token)
      this.$toast('登录成功')
      setTimeout(() => {
        this.$router.push('/myName')
      }, 300)
    },
    onClickLeft () {
      this.$router.back()
    }

  }
}
</script>

<style scoped>

/* .van-icon van-icon-arrow-left van-nav-bar__arrow {
  color: #333 !important;

} */
 ::v-deep .van-nav-bar .van-icon {
  color: #333 !important;
}
.link {
  color: #666;
  text-align: center;

}
 .ccc {
    color: #ccc;
  }
</style>
